<?php

/**
 * @name ScriptManager
 * @author Roman Metlinskyi <r.metlinskyi@gmail.com>
 */

class ScriptManager extends Object
{
    
  private $_js;
  private $_css;
  
  private static $_scriptManager;

  private function __construct()
  {
    $this->_js = array();
    $this->_css = array();
  }
  
  private function __clone()
  {

  }

  public static function ScriptManager()
  {
    return (!isset(self::$_scriptManager)) ? (self::$_scriptManager = new self()) : self::$_scriptManager;
  }
  
/*
* Include java script file
*/
  public function js($key, $src){
    $this->_js[$key] = $src;
    return $this;
  }
 
/*
* Include style sheet file
*/
  public function css($key, $href){
    $this->_css[$key] = $href;
    return $this;
  }
  
  public function JavaScript(){
    foreach($this->_js as $src){
        echo $this->script($src);
    }
  }
  
  public function StyleSheet(){
    foreach($this->_css as $href){
        echo $this->link($href);
    }
  }
  
  private function script($src){
    return "<script src='{$src}'></script>";
  }
  
  private function link($href, $rel = 'stylesheet'){
    return "<link href='{$href}' rel='{$rel}' />";
  } 
}